Learnerslesson
   JAVA   
  SPRING  
  SPRINGBOOT  
 HIBERNATE 
  HADOOP  
   HIVE   
   ALGORITHMS   
   PYTHON   
   GO   
   KOTLIN   
   C#   
   RUBY   
   C++   




clear( ) FUNCTION


The clear( ) Function is used to remove all the elements of the List.


Example :


x = ["Mohan", "Kriti", "Salim"]
x.clear()
print(x) 


Output :



  [ ]

So, in the above code we have created a 'List' and initialised to the variable 'x'.


x = ["Mohan", "Kriti", "Salim"]

Below is how the values are positioned in the List,


java_Collections

Next, we have used the 'clear( )' function that removes all the elements from the List making the List empty.


And we get an empty List as output,


[ ]